package top.ahzy.seobench.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.ahzy.seobench.model.entity.User;
import top.ahzy.seobench.model.req.PageParam;
import top.ahzy.seobench.model.req.UserEditReq;
import top.ahzy.seobench.model.req.UserLoginReq;
import top.ahzy.seobench.model.rsp.UserLoginRsp;
import top.ahzy.seobench.result.Result;
import top.ahzy.seobench.result.ResultList;
import top.ahzy.seobench.service.UserService;

import javax.validation.Valid;
@Validated
@RestController
@RequestMapping("/user")
@Api(tags = "用户模块")
public class UserController {

    @Autowired
    private UserService userService;

    @PostMapping("/login")
    @ApiOperation(value = "登录", notes = "")
    public Result<UserLoginRsp> login(@RequestBody @Valid UserLoginReq param) {
        return userService.login(param);
    }

    @PostMapping("/out")
    @ApiOperation(value = "退出", notes = "")
    public Result<String> out() {
        return userService.out();
    }

    @PostMapping("/edit")
    @ApiOperation(value = "编辑用户", notes = "")
    public Result<String> edit(@RequestBody @Valid UserEditReq param) {
        return userService.edit(param);
    }

    @PostMapping("/list")
    @ApiOperation(value = "列表", notes = "")
    public Result<ResultList<User>> list(PageParam param) {
        return userService.list(param);
    }
}
